package StringOperation.test4_19;

public class FindHuiWen {

    public String longestPalindrome(String s) {
        String res="";
        int length = s.length();
        for (int i = 0; i < length; i++) {
            String s1 = palindrome(s, i, i);
            String s2 = palindrome(s, i, i + 1);
            res=s1.length()>res.length()?s1:res;
            res=s2.length()>res.length()?s2:res;
        }

        return  res;
    }

    public  String  palindrome(String  s,int i,int j){
        while (i>0&&j<s.length()&&s.charAt(i)==s.charAt(j)){
            i--;
            j++;
        }
        //  CKG TODO 2023/4/19: 没有找到回文串
        if (i+1>j-1){
            return "";
        }

        return s.substring(i+1,j);

    }

    public static void main(String[] args) {
        FindHuiWen findHuiWen = new FindHuiWen();
        String abc = findHuiWen.longestPalindrome("abbcb");
        System.out.println(abc);
    }



}


